package pl.edu.utp.kursy.database.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import pl.edu.utp.kursy.database.InoviceRow;

public class InoviceRowDao extends BaseDao<InoviceRow>{
    
    public InoviceRowDao(SessionFactory sessionFactory){
        super(sessionFactory);
    }
    
    @Override
    public InoviceRow getById(int id) {
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(InoviceRow.class);
        c.add(Restrictions.eq("id", id));    		    		
        InoviceRow inoviceRow = (InoviceRow)c.uniqueResult();
        session.close(); 
        return inoviceRow; 
    }

    @Override
    public List<InoviceRow> getAll() {
        ArrayList<InoviceRow> rows;
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(InoviceRow.class);
        c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        rows = (ArrayList<InoviceRow>)c.list();
        session.close();
        return rows;  
    }
}